﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using ITAP.Core.Modelling.Primitives;
using ITAP.Core.Modelling;

namespace ITAP.ContourBuilder.Components.Dimensions
{
    [Serializable]
    public class ArcHeightDimension : ContourElementDimension
    {
        public override double OffsetFromPrimitive
        {
            get
            {
                return 0;
            }
            set
            {
            }
        }

        public override string DimensionText
        {
            get
            {
                if (this.connectedComponents.Count != 1)
                    throw new Exception();

                if (this.PrefixSymbol != String.Empty)
                    return this.PrefixSymbol + " = " + Math.Abs(this.Element.Height).ToString("0.0");
                else
                    return this.Element.Height.ToString("0.0");
            }
        }

        public override void MoveWithOffset(ModelVector offset)
        {            
        }

        public override void Recalculate()
        {
            ContourElement element = this.Element;
            if (element != null)
            {
                ModelPoint centerLinePoint = new ModelPoint((element.StartPoint.X + element.EndPoint.X) / 2, (element.StartPoint.Y + element.EndPoint.Y) / 2);
                ModelPoint centerArcPoint = element.Primitive.GetPoint(0.5);
                this.Primitive = new Line(centerLinePoint, centerArcPoint);
            }
        }

        public override void AcceptDimensionVisitor(IDimensionVisitor visitor)
        {
            visitor.Visit(this);
        }
    }

}
